﻿using System.IO;
using UnityEngine;

namespace Utils.FileFolderModule
{
    public static class FileHandler
    {
        public static bool CreateFile(string filePath)
        {
            if (File.Exists(filePath))
            {
                return false;
            } 
            new FileInfo(filePath).CreateText();
            return File.Exists(filePath);
        }

        public static bool DeleteFile(string filePath)
        {
            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
            return File.Exists(filePath);
        }
        
        public static string ReadFileContent(string filePath)
        {
            return File.ReadAllText(filePath);
        }

        public static void ReWriteFile(string filePath, string content)
        {
            StreamWriter sw = new FileInfo(filePath).CreateText();
            sw.WriteLine(content);
            sw.Close();
            sw.Dispose();
        }

        public static void AppendWriteFile(string filePath, string content)
        {
            StreamWriter sw = new FileInfo(filePath).AppendText();
            sw.WriteLine(content);
            sw.Close();
            sw.Dispose();
        }
    }
}